package com.zhu.pre.controller;

import com.zhu.pre.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by zhu yingzhi on 2017/10/17.
 * @author yingzhi zhu
 * 手机接口路由类
 */
@RestController
@RequestMapping("/m/category")
public class MCategoryController {
    @Autowired
    private CategoryService categoryService;


    /**
     * 查找某一Pid下的下一级子分类
     * @param parentPid 为0代表一级分类
     *
     * @return
     */
    @GetMapping(value = "/child")
    public Object getCategory(@RequestParam String parentPid){

        return categoryService.findByParentPid(parentPid);
    }



    /**
     * 通过pid 查找某个接口
     * @param pid 唯一标识符
     * @return
     */
    @GetMapping(value = "/{pid}")
    public Object putCategory(@PathVariable String pid){
        return categoryService.findOne(pid);
    }

    /**
     * 获取所有的分类
     * @return
     */
    @GetMapping(value = "/all")
    public Object getCategoryAll(){
        return categoryService.mFindAll();
    }
}
